//
//  NSString+Exit.m
//  OpenDoor
//
//  Created by cnmobi on 15/7/10.
//  Copyright (c) 2015年 CNMOBI. All rights reserved.
//

#import "NSString+Exit.h"

@implementation NSString(NSString_Exit)


- (id)JSONValue {
    
    NSData *jsonData = [(NSString *)self dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    id value = [NSJSONSerialization JSONObjectWithData:jsonData
                                                        options:NSJSONReadingMutableContainers
                                                          error:&err];
    if(err) {
        DLog(@"json解析失败：%@",err);
        return nil;
    }
    return value;
}

- (NSString *)judgeWithBase:(NSString *)baseStr
{
    return [self isEqualToString:@""]?[NSString stringWithFormat:@"%@无",baseStr]:[NSString stringWithFormat:@"%@%@",baseStr,self];
    
}
- (NSString *)judgeRoomBase:(NSString *)baseStr
{
    return [self isEqualToString:@""]?[NSString stringWithFormat:@"%@无",baseStr]:[NSString stringWithFormat:@"%@",self];
}


//：后 “无”是灰色，其他黑色
- (NSAttributedString *)judgeAttributeBase:(NSString *)baseStr
{
    NSString *selfStr = [self isEqualToString:@""]?[NSString stringWithFormat:@"%@无",baseStr]:[NSString stringWithFormat:@"%@%@",baseStr,self];
    
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc]initWithString:selfStr];
    if ([selfStr rangeOfString:@"："].location == NSNotFound) {
        return string;
    }
    NSRange subRange= [selfStr rangeOfString:[selfStr substringFromIndex:[selfStr rangeOfString:@"："].location+1]];
    
    NSArray *colors=[NSArray arrayWithObjects:[UIColor blackColor],[self isEqualToString:@""]?[UIColor grayColor]:[UIColor blackColor],nil];
    
    [string addAttribute:NSForegroundColorAttributeName value:[colors objectAtIndex:1] range:subRange];
    
    return string;
}
//价格：后 “无”是灰色，其他￥黑色
- (NSAttributedString *)judgeAttributePrice:(NSString *)baseStr
{
    NSString *selfStr = [self isEqualToString:@""]||[self isEqualToString:@"0"]?[NSString stringWithFormat:@"%@未填写",baseStr]:[NSString stringWithFormat:@"%@￥%@",baseStr,self];
    
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc]initWithString:selfStr];

    NSRange subRange= [selfStr rangeOfString:[selfStr substringFromIndex:[selfStr rangeOfString:@"："].location+1]];
    
    NSArray *colors=[NSArray arrayWithObjects:[UIColor blackColor],[self isEqualToString:@""]||[self isEqualToString:@"0"]?[UIColor grayColor]:[UIColor blackColor],nil];
    
    [string addAttribute:NSForegroundColorAttributeName value:[colors objectAtIndex:1] range:subRange];
    
    return string;
}
//：后 “无”是灰色，其他去掉：冒号以前的，显示黑色
- (NSAttributedString *)judgeAttributeRoom:(NSString *)baseStr
{
    NSString *selfStr = [self isEqualToString:@""]?[NSString stringWithFormat:@"%@无",baseStr]:[NSString stringWithFormat:@"%@",self];
    
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc]initWithString:selfStr];
    if ([selfStr rangeOfString:@"："].location == NSNotFound) {
        return string;
    }
    NSRange subRange= [selfStr rangeOfString:[selfStr substringFromIndex:[selfStr rangeOfString:@"："].location+1]];
    
    NSArray *colors=[NSArray arrayWithObjects:[UIColor blackColor],[self isEqualToString:@""]?[UIColor grayColor]:[UIColor blackColor],nil];
    
    [string addAttribute:NSForegroundColorAttributeName value:[colors objectAtIndex:1] range:subRange];
    
    return string;
}


//：后都是灰色
- (NSAttributedString *)judgeAttributeRemark:(NSString *)baseStr
{
    NSString *selfStr = [self isEqualToString:@""]?[NSString stringWithFormat:@"%@无",baseStr]:[NSString stringWithFormat:@"%@%@",baseStr,self];
    
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc]initWithString:selfStr];
    
    NSRange subRange= [selfStr rangeOfString:[selfStr substringFromIndex:[selfStr rangeOfString:@"："].location+1]];
    
    NSArray *colors=[NSArray arrayWithObjects:[UIColor blackColor],[UIColor grayColor],nil];
    
    [string addAttribute:NSForegroundColorAttributeName value:[colors objectAtIndex:1] range:subRange];
   
    return string;
}




@end
